{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="mb-20" method="get" action="{:\\think\\Url::build($Request.action)}">
        <input type="hidden" name="group_id" value="{$group_id}">
        <input type="text" class="input-text" style="width:250px" placeholder="姓名" name="realname" value="{$Request.param.realname}">
        <input type="text" class="input-text" style="width:250px" placeholder="手机号" name="mobile" value="{$Request.param.mobile}">
        <input type="text" class="input-text" style="width:250px" placeholder="车类型" name="car_type" value="{$Request.param.car_type}">
        <input type="text" class="input-text" style="width:250px" placeholder="车辆品牌" name="car_brand" value="{$Request.param.car_brand}">
        <input type="text" class="input-text" style="width:250px" placeholder="汽车型号" name="car_model" value="{$Request.param.car_model}">
        <input type="text" class="input-text" style="width:250px" placeholder="车辆等级" name="vehicle_level" value="{$Request.param.vehicle_level}">
        <input type="text" class="input-text" style="width:250px" placeholder="座位数" name="seats" value="{$Request.param.seats}">
        <input type="text" class="input-text" style="width:250px" placeholder="请输入民族" name="nationality" value="{$Request.param.nationality}">
        <div   style="width:250px;display: inline-block" >
            <select name="driver_rank_id" class="select2 " id="driver_rank_id">
                <option value="">选择等级</option>
                <option value="5">新手</option>
                {volist name="ranks" id="rank"}
                <option value="{$rank.id}">{$rank.name}</option>
                {/volist}
            </select>
        </div>
        <div style="width:250px;display: inline-block" >
            <select name="tag" class="select2 " id="tag">
                <option value="">选择标签</option>
                {volist name="driver_tags" id="driver_tag"}
                <option value="{$driver_tag.id}"  >{$driver_tag['chinese']}</option>
                {/volist}
            </select>
        </div>
        <button type="submit" class="btn btn-success" id="realname_btn" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
    </form>
    <!--select2 js 插件-->
    <script type="text/javascript" src="__LIB__/select2-4.0.3/dist/js/select2.min.js"></script>
    <!--select2样式 start -->
    <link href="__LIB__/select2-4.0.3/dist/css/select2.min.css" rel="stylesheet" />

    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
        <br>
        <?php use think\Db; ?>
        <form id="driverForm" action="###" onsubmit="return false" method="post">
            <input type="hidden" name="id" value="{$group_id}">
            <table class="table table-border table-bordered table-hover table-bg mt-20">
                <!--//头部搜索-start-->
                <thead>
                <tr class="text-c">
                    <th width="25">
                        <input type="checkbox" name="user_id[]" id="checkAlls">
                    </th>
                    <th width="">用户名</th>
                    <th width="">电话</th>
                    <th width="">车类型</th>
                    <th width="">车辆品牌</th>
                    <th width="">汽车型号</th>
                    <th width="">车辆等级</th>
                    <th width="">民族</th>
                    <th width="">座位数</th>
                    <th width="">是否在服务中</th>
                    <th width="">等级</th>
                    <th width="">标签</th>
                </tr>
                </thead>
                <tbody>
                {foreach name="list" item="vo" }
                    <tr>
                        {php}
                            // 查询用户信息
                            $userInfo = Db::name('admin_user')->where('id', $vo['user_id'])->find();
                            if(empty($userInfo)){
                                continue;
                            }
                        {/php}
                        <td style="text-align: center">
                            <input type="checkbox" name="user_id[]" {if (in_array($vo['user_id'],$check_user_ids))} checked {/if} value="{$vo.user_id}">
                        </td>
                        <td style="text-align: center">
                            {if (!empty($userInfo['realname']))}
                                {$userInfo['realname']}
                            {else /}
                                {$userInfo['account']}
                            {/if}
                        </td>
                        <td style="text-align: center">
                            {if (!empty($userInfo['mobile']))}
                                {$userInfo['mobile']}
                            {else /}
                                {$userInfo['account']}
                            {/if}
                        </td>
                        <td style="text-align: center">{$vo.car_type}</td>
                        <td style="text-align: center">{$vo.car_brand}</td>
                        <td style="text-align: center">{$vo.car_model}</td>
                        <td style="text-align: center">{$vo.vehicle_level}</td>
                        <td style="text-align: center">{$vo.nationality}</td>
                        <td style="text-align: center">{$vo.seats}</td>
                        <td style="text-align: center">{$vo.inservice}</td>
                        <td style="text-align: center">{$vo.driver_rank_id}</td>
                        <td>
                            {php}
                                if($vo['tag']){
                                    $tag = Db::name('driver_tag')->where('id','in',$vo['tag'])->field('chinese')->select();
                                    $tagStr = '';
                                foreach($tag as $tk=>$tv){
                                    $tagStr .= $tv['chinese'].',';
                                }
                                 echo rtrim($tagStr,',');
                                }
                            {/php}
                        </td>
                    </tr>
                {/foreach}
                </tbody>
            </table>
            <div class="page-bootstrap">{$page ?? ''}</div>
            <div class="row cl">
                <div class="col-xs-9 col-sm-8 col-xs-offset-4 col-sm-offset-5">
                    <button type="submit" id="submit" class="btn btn-primary radius" onclick="submitDriver()">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                    <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                </div>
            </div>

        </form>
    </div>
    {/block}
    {block name="script"}
    <script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script>
    <script type="text/javascript" src="__LIB__/template/template.js"></script>
    <script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script>

    <script>
        function submitDriver() {
            // 获取父页的窗口索引
            var index = parent.layer.getFrameIndex(window.name);
            // 获取选择的用户id
            var idAll = $("input:checked[name='user_id[]']");
            var idAllData = idAll.serializeArray();
            if (idAllData.length == 0){
                layer.msg('你没有选择司机');
            }else{
                var len = idAllData.length;
                var idStr = '';
                for (var i = 0; i < len; i++) {
                    // console.log('选择用户', idAllData[i])
                    if (idAllData[i].value != 'on'){
                        idStr += idAllData[i].value + ',';
                    }
                }
                idStr = idStr.substr(0, idStr.length - 1);
                // console.log('所有用户的id字符串', idStr)
                // 获取用户名
                $.ajax({
                    type: 'post',
                    url: '/admin/notify/getDriverInfos',
                    data: { user_id: idStr },
                    success: function (ret) {
                        console.log('ret', ret)
                        if (ret.code == 0){
                            console.log('长度', ret.data.length)
                            if (ret.data.length > 0){
                                var data = ret.data;
                                var dataLen = ret.data.length;
                                var dataStr = '';
                                for (var k = 0; k < dataLen; k++) {
                                    dataStr += data[k] + ',';
                                }
                                dataStr = dataStr.substr(0, dataStr.length - 1);
                                parent.$('#user_id').text(dataStr);
                                parent.layer.msg('选择司机成功', {icon: 6});
                                // console.log('选择的用户列表: ', dataStr)
                                parent.layer.close(index); // 关闭弹窗页
                            }
                        }
                    }
                });
            }
        }
    </script>
    <script>
        $(function () {
            $(function () {
                var tag = $("#tag").select2({
                    language: "zh-CN", //设置 提示语言
                    width: "100%", //设置下拉框的宽度
                    theme: "classic"
                });
                {notempty name = "Request.param.tag"}
                tag.val("{$Request.param.tag}").trigger("change");
                {/notempty}
                })
            var driver_rank_id = $("#driver_rank_id").select2({
                language: "zh-CN", //设置 提示语言
                width: "100%", //设置下拉框的宽度
                theme: "classic"
            });
            {notempty name = "Request.param.driver_rank_id"}
            driver_rank_id.val("{$Request.param.driver_rank_id}").trigger("change");
            {/notempty}

            })
    </script>
    {/block}
